<?php
class Nguyen_System{
	public function BaseUrl(){
		$fc = Zend_Controller_Front::getInstance();
        return  $fc->getBaseUrl();
	}
	function getCurrentPageURL() {
	    $pageURL = 'http';
	    $pageURL .= "://";
	    if ($_SERVER["SERVER_PORT"] != "80") {
	        $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"];
	    } else {
	        $pageURL .= $_SERVER["SERVER_NAME"];
	    }
	    return $pageURL;
	}
	public function checkUrl($str){
		$temp = substr($str,0,7);
		return  ($temp == "http://")?true:false;
	}
	public function curentday(){
		$today = getdate();
		$str = $today['year'].'-'. $today['mon'].'-'. $today['mday'].' '.$today['hours'].'-'. $today['minutes'].'-'. $today['seconds'];
		return $str;
	}
	public function ValidatePass($str1,$str2){
		if ($str1==$str2){
			return true;
		}
		return false;
	}
	public function ConvStrToDate($str){
		$result = array();
		$aray = explode(' ', $str);	
		$date = $aray[0];
		$kq1 = explode('-', $date);
		$result['year'] = $kq1[0];
		$result['month'] = $kq1[1];
		$result['day'] = $kq1[2];
		$time = $aray[1];	
		$kq2 = explode(':', $time);
		$result['hour'] = $kq2[0];
		$result['minute'] = $kq2[1];
		$result['second'] = $kq2[2];
		return $result;
	} 
	public function TrimWord($str,$count){
		$array = explode(' ', $str);
		$result = '';
		if($count>count($array)) return $str;
		for ($i = 0; $i < $count; $i++) {
			$result .= $array[$i].' ';
		}
		return $result;
	}
	public function FormatFloatNumber($number){
		$result = '';$first = '';
		$leng = strlen($number);
		$count =  $leng%3;
		$first = substr($number,0, $count);
		$second = substr($number,$count);
		$result .= $first;
		$arr = str_split($second,3);
		foreach ($arr as $value) {
			$result .= ' '.$value;
		}
		$result = trim($result);
		$result = str_replace(' ', ',',$result);
		return $result;
	}
	function vn_str_filter ($str){
        $unicode = array(
            'a'=>'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ',
            'd'=>'đ',
            'e'=>'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ',
            'i'=>'í|ì|ỉ|ĩ|ị',
            'o'=>'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ',
            'u'=>'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự',
            'y'=>'ý|ỳ|ỷ|ỹ|ỵ',
			'A'=>'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',
            'D'=>'Đ',
            'E'=>'É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',
            'I'=>'Í|Ì|Ỉ|Ĩ|Ị',
            'O'=>'Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',
            'U'=>'Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',
            'Y'=>'Ý|Ỳ|Ỷ|Ỹ|Ỵ',
        );
       foreach($unicode as $nonUnicode=>$uni){
            $str = preg_replace("/($uni)/i", $nonUnicode, $str);
       }
       $str = str_replace("?"," ",$str);
       $str = str_replace(" ","-",$str);
		return $str;
    }
}